Skip to content

Add cleanup of old account events #6576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions kitsune/users/management/commands/cleanup_old_account_events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.core.management.base import BaseCommand
from django.utils import timezone
from datetime import timedelta
from kitsune.users.models import AccountEvent


class Command(BaseCommand):
help = "Deletes account events that are older than two years"

def handle(self, *args, **options):
two_years_ago = timezone.now() - timedelta(days=730) # 2 years * 365 days
deleted_count = AccountEvent.objects.filter(created_at__lt=two_years_ago).delete()[0]
self.stdout.write(
self.style.SUCCESS(f"Successfully deleted {deleted_count} old account events")
)
17 changes: 17 additions & 0 deletions kitsune/users/migrations/0033_delete_old_account_events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.db import migrations
from django.core.management import call_command


def cleanup_old_account_events(apps, schema_editor):
call_command('cleanup_old_account_events')


class Migration(migrations.Migration):

dependencies = [
('users', '0032_profile_account_type_alter_profile_user'),
]

operations = [
migrations.RunPython(cleanup_old_account_events, migrations.RunPython.noop),
]
15 changes: 15 additions & 0 deletions scripts/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,21 @@ def job_update_l10n_contributor_metrics():
call_command("update_l10n_contributor_metrics")


@scheduled_job(
"cron",
month="*",
day="*",
hour="02",
minute="00",
day_of_week=0,
max_instances=1,
coalesce=True,
skip=settings.READ_ONLY,
)
def job_cleanup_old_account_events():
call_command("cleanup_old_account_events")


def run():
try:
schedule.start()
Expand Down